const mongoose = require('mongoose')

const { Schema, model } = mongoose;

const userSchema = new Schema({
  __v: { type: Number, select: false },
  // 用户名
  name: { type: String, required: true },
  // 密码
  password: { type: String, required: true, select: false }, // select: false 不返回密码
  // 头像
  avatar_url: { type: String },
  // 性别
  gender: { type: String, enum: ['male', 'female'], default: 'male', required: true }, // enum 表示可枚举
  // 简介
  headline: { type: String },
  // 居住地址
  locations: { type: [{ type: Schema.Types.ObjectId, ref: 'Topic' }], select: false  },
  // 行业
  business: { type: Schema.Types.ObjectId, ref: 'Topic', select: false  },
  // 职业经历
  employments: {
    type: [{
      company: { type: Schema.Types.ObjectId, ref: 'Topic' },
      job: { type: Schema.Types.ObjectId, ref: 'Topic' }
    }],
    select: false 
  },
  // 教育经历
  educations: {
    type: [{
      school: { type: Schema.Types.ObjectId, ref: 'Topic' },
      // 专业
      major: { type: Schema.Types.ObjectId, ref: 'Topic' },
      // 学历
      diploma: { type: Number, enum: [1, 2, 3, 4, 5] },
      // 入学年份
      entrance_year: { type: Number },
      graduation_year: { type: Number }
    }],
    select: false 
  },
  // 关注用户
  following: {
    // Schema.Types.ObjectId 为mongoDB的类型
    // ref 关联 User 
    type: [{ type: Schema.Types.ObjectId, ref: 'User' }],
    select: false
  },
  // 关注话题
  followingTopics: {
    type: [{ type: Schema.Types.ObjectId, ref: 'Topic' }],
    select: false
  },
  // 赞过的答案
  likingAnswers: {
    type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
    select: false
  },
  // 踩的答案
  dislikingAnswers: {
    type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
    select: false
  },
  // 收藏的答案
  collectingAnswers: {
    type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
    select: false
  }
}, { timestamps: true })
module.exports = model('User', userSchema)